var t = getApp(), a = require("../../utils/util.js"), e = null;

Page({
    data: {
        showSetting: !1,
        canUserSetVIP: !1,
        videoAdLoading: !1,
        status: {
            curMs: 1500,
            max: 3e3,
            min: 500,
            curShape: 0
        },
        shapes: [ {
            name: "心跳模式",
            animation: "beatting"
        }, {
            name: "心爆模式",
            animation: "beatting1"
        } ]
    },
    videoAdLoad: function() {
        var a = this;
        if (1 != this.data.videoAdLoading) return null != e ? (this.setData({
            videoAdLoading: !0
        }), this.videoAdShow()) : void (wx.createRewardedVideoAd && (this.setData({
            videoAdLoading: !0
        }), (e = wx.createRewardedVideoAd({
            adUnitId: t.ad.jlAd_02,
            multiton: !0
        })).onLoad(function() {
            1 == a.data.videoAdLoading && a.videoAdShow();
        }), e.onError(function(t) {
            e = null, a.setData({
                videoAdLoading: !1
            });
        }), e.onClose(function(t) {
            a.setData({
                videoAdLoading: !1
            }), t && t.isEnded && (a.setData({
                canUserSetVIP: !0
            }), wx.setStorageSync("canUserSetHeartData", {
                canUserSetVIP: !0,
                time: Date.parse(new Date())
            }));
        })));
    },
    onShow: function() {
        try {
            var t = wx.getStorageSync("heartbeatCache");
            t && this.setData({
                status: t
            });
        } catch (t) {}
        this.canUserSetVIPHandle();
    },
    showModal: function(t) {
        this.setData({
            showSetting: !0
        });
    },
    hideModal: function() {
        wx.setStorageSync("heartbeatCache", this.data.status), this.setData({
            showSetting: !1
        });
    },
    shapeChange: function(t) {
        var a = this;
        t.detail.value >= 0 ? a.data.canUserSetVIP ? this.setData({
            "status.curShape": t.detail.value
        }) : (a.setData({
            "status.curShape": 0
        }), wx.showModal({
            title: "屏幕心跳",
            content: "心爆模式\n\r\n\r需要观看广告后才可以设置哦\n\r\n\r😍 怎么这么帅 😍\n\r😍 太帅了 😍\n\r😍 帅 😍\n\r😍",
            confirmText: a.data.videoAdLoading ? "加载中" : "立即观看",
            showCancel: !a.data.videoAdLoading,
            cancelText: "取消",
            success: function(t) {
                t.confirm && a.videoAdLoad();
            }
        })) : this.setData({
            "status.curShape": t.detail.value
        }), wx.setStorageSync("heartbeatCache", this.data.status);
    },
    catchtap: function() {},
    canvasTouchStart: function() {
        this.showModal();
    },
    msChange: function(t) {
        this.setData({
            "status.curMs": t.detail.value
        }), wx.setStorageSync("heartbeatCache", this.data.status);
    },
    videoAdShow: function() {
        var t = this;
        e && e.show().catch(function() {
            t.setData({
                videoAdLoading: !1
            }), e.load().then(function() {
                return e.show();
            }).catch(function(t) {
                a.videoAdErrCodeHandle(t);
            });
        });
    },
    canUserSetVIPHandle: function() {
        try {
            var t = wx.getStorageSync("canUserSetHeartData");
            "" != t && ((Date.parse(new Date()) - t.time) / 1e3 < 86400 ? this.setData({
                canUserSetVIP: !0
            }) : (this.setData({
                "status.curShape": 0
            }), wx.setStorageSync("heartbeatCache", this.data.status)));
        } catch (t) {}
    }
});